package com.xinnet.mms.customerConsumeManage.dao.impl;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Repository;

import com.xinnet.core.dao.impl.BaseDaoImpl;
import com.xinnet.core.utils.page.PageView;
import com.xinnet.mms.customerConsumeManage.dao.CustomerConsumeManageDao;
import com.xinnet.mms.entity.Customer;
import com.xinnet.mms.entity.CustomerConsume;
import com.xinnet.mms.entity.Emp;

@Repository("customerConsumeManageDao")
public class CustomerConsumeManageDaoImpl extends BaseDaoImpl<Customer,Long> implements CustomerConsumeManageDao{

	@Override
	public List<CustomerConsume> queryCustomerConsume(
			PageView<CustomerConsume> pageView, CustomerConsume customerConsume) {
		Integer startPage = pageView.getFirstResult();
		customerConsume.setLimitTop(startPage);
		customerConsume.setLimitDown(pageView.getPageSize());
		return super.getSqlSession().selectList("customerConsume.queryCustomerConsumeList", customerConsume);
	}

	@Override
	public List<CustomerConsume> queryCustomerConsumeForCount(
			CustomerConsume customerConsume) {
		return super.getSqlSession().selectList("customerConsume.queryCustomerConsumeForCount", customerConsume);
	}

	@Override
	public int count(CustomerConsume customerConsume) {
		return super.getSqlSession().selectOne("customerConsume.count", customerConsume);
	}


	@Override
	public void addCustomerConsume(CustomerConsume customerConsume) {
		 
		super.getSqlSession().insert("customerConsume.addCustomerConsume", customerConsume);
	}

	@Override
	public void updateCustomerConsume(CustomerConsume customerConsume) {
		 
		super.getSqlSession().update("customerConsume.updateCustomerConsume", customerConsume);
	}
	
	@Override
	public void delCustomerConsume(CustomerConsume customerConsume) {
		 
		super.getSqlSession().delete("customerConsume.delCustomerConsume", customerConsume);
	}

	@Override
	public void updateCustomerConsumeEmp(Customer customer, Emp emp) {
		Map<Object, Object> map = new HashMap<Object, Object>();
		map.put("fromEmpId", customer.getEmpId());
		map.put("toEmpId", emp.getEmpno());
		map.put("cusId", customer.getCusId());
		super.getSqlSession().update("customerConsume.updateCustomerConsumeEmp", map);
	}
	
	@Override
	public void updateCustomerConsumeCusId(Customer reported, Customer customer) {
		Map<Object, Object> map = new HashMap<Object, Object>();
		map.put("toSet", customer.getCusId());
		map.put("toWhere", reported.getCusId());
		super.getSqlSession().update("customerConsume.updateCustomerConsumeCusId", map);
	}
}
